#!/usr/bin/env bash
# ---------------------------------------------------------------
# File          : uninstall.sh
# Authors       : ccmywish <ccmywish@qq.com>
# Created on    : <2021-01-06>
# Last modified : <2021-01-06>
#
# uninstall:
#
#   Uninstall nvm wholly
# ---------------------------------------------------------------

# echo "=> 删除~/.nvm"
# rm -rf $HOME/.nvm
if [[ -z $NVM_DIR ]]; then
  export NVM_DIR="$HOME/.nvm"
fi
echo "=> 删除NVM_DIR"
rm -rf $NVM_DIR

echo "=> 删除相关环境变量"
sed -i '/nvm config/d' "${HOME}/.bashrc"
sed -i '/This loads nvm/d' "${HOME}/.bashrc"
sed -i '/NVM_NODEJS_ORG_MIRROR/d' "${HOME}/.bashrc"

sed -i '/nvm config/d' "${HOME}/.zshrc"
sed -i '/This loads nvm/d' "${HOME}/.zshrc"
sed -i '/NVM_NODEJS_ORG_MIRROR/d' "${HOME}/.zshrc"

sed -i '/NODEJS_ORG_MIRROR/d' "/etc/profile"
sed -i '/NVM_DIR/d' "/etc/profile"
sed -i '/nvm.sh/d' "/etc/profile"
sed -i '/\/nvm\//d' "/etc/profile"

echo "=> 删除nvm-update"
sudo rm  /usr/local/bin/nvm-update
echo "=> 卸载完成!"